/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package bs.stock.dao;

import bs.global.dao.BaseDAO;
import bs.global.dao.BaseDAO;
import bs.global.modelo.ComprobantePK;
import bs.stock.modelo.ComprobanteStock;
import java.util.List;
import javax.ejb.Stateless;

/**
 *
 * @author Claudio
 */
@Stateless
public class ComprobanteInventarioDAO extends BaseDAO {

    public ComprobanteStock getComprobante(ComprobantePK idPK){

        return em.find(ComprobanteStock.class, idPK);
    }

    public Integer getUltimoNumeroComprobante(String modfor, String codfor){

        try {
            String query = "SELECT Max(PDRMVH_NROFOR) "
                    + "FROM pdrmvh "
                    + "WHERE PDRMVH_MODFOR = '" + modfor + "' "
                    + "AND PDRMVH_CODFOR = '" + codfor + "'";

            Integer ultNumero = (Integer) em.createNativeQuery(query).getSingleResult();

//            System.out.println("ultimo numero obtenido: " + ultNumero);

            if(ultNumero==null) return 0;
            else return ultNumero;

        } catch (Exception e) {
            e.printStackTrace();
            System.err.println("Error al consultar ultimo número: " + e.getMessage());
            return -1;
        }

    }

    public List<ComprobanteStock> getLista() {
        return getLista(ComprobanteStock.class, true , -1, -1);
    }

    
    
    // Add business logic below. (Right-click in editor and choose
    // "Insert Code > Add Business Method")
 
}
